#include <fstream>
#include <iostream>
#include <iomanip>
#include <math.h>
#include "ivp.h"
#include "ode_util.h"
#include "explicit_euler.h"
#include "implicit_euler.h"
#include "implicit_tr.h"
#include "rk4.h"
#include "bdf.h"
#include "vbdf.h"

using namespace std;
class Tst
{
public:
 double x,y;
 void sum(int n,double * k,Tst** arr)
 {
  int i;
  x=y=0;
  for(i=0;i<n;i++)
  {
   x+=arr[i]->x*k[i];
   y+=arr[i]->y*k[i];
  }
 }
 double norm2() const {return x*x+y*y;}
};

class Tmivp:public Tivp<Tst,double>
{
public:
 double l1,l2;
 virtual void mul(double t,const Tst& from,Tst& to) const
 {
  to.x=l1*from.x;
  to.y=l2*from.y;
 }
 virtual void solve(double t,double d,const Tst& from,Tst& to) const
 {
  to.x=from.x/(1+d*l1);
  to.y=from.y/(1+d*l2);
 }
};

int main()
{
 float te=5;
 Tmivp ivp;
 ivp.l1=-1;
 ivp.l2=-10;

// Tbdf<Tst,double> eode(&ivp);
// Texplicit_euler<Tst,double> eode(&ivp);
 Timplicit_euler<Tst,double> eode(&ivp);
 eode.x.x=1;
 eode.x.y=1;
// eode.od=4;
 eode.h=0.1;
 eode.t=0;
// eode.h_new=1;
 for(;eode.t<te;eode++)
 {
  cout<<setw(12)<<eode.t<<setw(15)<<eode.x.x<<setw(15)<<eode.x.y<<endl;
//  eode.find_k_bdf();
 }
 return 0;
}

